package com.ruoyi.asset.toilet.controller;


import cn.dev33.satoken.annotation.SaIgnore;
import com.ruoyi.asset.toilet.domain.bo.ToiletMaintenanceBo;
import com.ruoyi.asset.toilet.domain.bo.ToiletStatisticsBo;
import com.ruoyi.asset.toilet.domain.vo.ToiletCommunityCountVo;
import com.ruoyi.asset.toilet.domain.vo.ToiletCommunityMapVo;
import com.ruoyi.asset.toilet.domain.vo.ToiletMaintenanceVo;
import com.ruoyi.asset.toilet.domain.vo.ToiletWorkStatisticsVo;
import com.ruoyi.asset.toilet.service.IToiletMaintenanceService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.system.domain.vo.SysOssVo;
import com.ruoyi.system.service.ISysOssService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 公厕管养
 *
 * @author 12276
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/asset/toilet")
public class ToiletMaintenanceController extends BaseController {

    private final IToiletMaintenanceService toiletService;

    /**
     * 获取公厕管养-管理范围导入模板
     */
    @SaIgnore()
    @Log(title = "清扫公厕管养范围导入", businessType = BusinessType.IMPORT)
    @RepeatSubmit()
    @PostMapping(value = "/importData")
    public R<List<String>> importData(@RequestParam(name = "excelUrl") String excelUrl) {
        List<String> list = this.toiletService.importExcel(excelUrl);

        if (list == null) {
            return R.fail();
        } else {
            return R.ok(list);
        }
    }

    /**
     * 获取公厕管养-管理范围导入模板
     */
    @SaIgnore()
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil.exportExcel(new ArrayList<>(), "公厕管养管理范围导入模板", ToiletMaintenanceVo.class, response);
    }

    /**
     * 删除公厕管养范围
     */
    @SaIgnore()
    @DeleteMapping("/deleteToilet/{ids}")
    public R<Void> deleteToilet(@NotEmpty(message = "主键不能为空")
                                          @PathVariable Set<Long> ids) {
        int count = this.toiletService.deleteToilet(ids);

        return toAjax(count >= 0 ? 1 : count);
    }

    /**
     * 查询公厕管养范围
     */
    @SaIgnore()
    @GetMapping("/queryToilet")
    public TableDataInfo<ToiletMaintenanceVo> queryToilet(ToiletMaintenanceBo searchBo, PageQuery pageQuery) {
        return this.toiletService.queryToilet(searchBo, pageQuery);
    }

    /**
     * 导出公厕管养范围
     */
    @SaIgnore()
    @Log(title = "公厕管养范围导出", businessType = BusinessType.EXPORT)
    @PostMapping("/exportToilet")
    public void exportToilet(ToiletMaintenanceBo searchBo, HttpServletResponse response) {
        List<ToiletMaintenanceVo> list = this.toiletService.exportToilet(searchBo);

        ExcelUtil.exportExcel(list, "公厕管养范围", ToiletMaintenanceVo.class, response);
    }

    @SaIgnore()
    @GetMapping("/toiletCount")
    public R<ToiletStatisticsBo> toiletCount() {
        ToiletStatisticsBo toiletCount = toiletService.getToiletCount();
        return R.ok(toiletCount);
    }

    @SaIgnore()
    @GetMapping("/toiletCommunityCount")
    public R<Map> toiletCommunityCount() {
        Map map = toiletService.getToiletCommunityCount();
        return R.ok(map);
    }

    /**
     * 查询智慧大屏市政公厕玉塘街道全社区
     * @param date
     * @return
     */
    @SaIgnore()
    @GetMapping("/toiletCommunity")
    public R<List<ToiletCommunityCountVo>> toiletCommunity(String date) {
        List<ToiletCommunityCountVo> toiletCountByCommunity = toiletService.getToiletCountByCommunity(date);
        return R.ok(toiletCountByCommunity);
    }

    /**
     * 查询智慧大屏市政公厕今日作业统计与百分比
     * @param date
     * @return
     */
    @SaIgnore()
    @GetMapping("/toiletWorkByDate")
    public R<ToiletWorkStatisticsVo> toiletWorkByDate(String date) {
        date = "2024-03-13";
        ToiletWorkStatisticsVo toiletWorkByDate = toiletService.getToiletWorkByDate(date);
        return R.ok(toiletWorkByDate);
    }

    /**
     * 查询智慧大屏市政公厕今日作业统计与百分比 指定社区
     * @param date
     * @param community
     * @return
     */
    @SaIgnore()
    @GetMapping("/toiletWorkByDateAndCommunity")
    public R<ToiletWorkStatisticsVo> toiletWorkByDateAndCommunity(String date, String community) {
        date = "2024-03-13";
        ToiletWorkStatisticsVo toiletWorkByDate = toiletService.getToiletWorkByDateAndCommunity(date,community);
        return R.ok(toiletWorkByDate);
    }


    /**
     * 查询智慧大屏市政公厕按社区区分
     * @param community
     * @param date
     * @return
     */
    @SaIgnore()
    @GetMapping("/communityByDate")
    public R<ToiletCommunityMapVo> communityByDate(String community, String date) {
        date = "2024-03-13";
        ToiletCommunityMapVo communityByDate = toiletService.getCommunityByDate(community, date);
        return R.ok(communityByDate);
    }
}
